import static org.junit.Assert.*;
import junit.framework.Assert;

import org.junit.Test;

import DBLayer.DbConnection;
import DBLayer.DbSupplier;
import ModelLayer.Supplier;


public class _TestSupplierDB {
	
	DbSupplier dbSupplier = new DbSupplier();;
	Supplier sup = new Supplier(18, "filip", "kastetsvej 45, 9200 Aalborg, Denmark", "871366", "yahoo@filip.com", "Filip Studio", "123");
	
	@Test
	public void test() 
	{
		//testFindSup(18);
		//testInsert();
		//testDelete(18);
		testUpdate(18);
	}
	
	
	void testUpdate(int idd)
	{
		sup.setAddress("new address for update 9000");
		sup.setCvr("999");
		int rc = dbSupplier.update(sup);
		
		Assert.assertEquals(1, rc);
	}
	
	
	void testFindSup(int idd)
	{
		Supplier sup = null;
		try {
			sup = (Supplier) dbSupplier.find_byID(idd);
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		Assert.assertNotNull(sup);
	}
	
	void testDelete(int idd)
	{
		
		int rc = -1;
		try {
			rc = dbSupplier.delete(idd);
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		Assert.assertEquals(1, rc);
		
	}
	
	void testInsert()
	{
		int rc = -1;
		try {
			rc = dbSupplier.insert(sup);
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		Assert.assertEquals(1, rc);
	}
	

}
